import { service } from './service'

import type { CustomAxiosRequestConfig } from './setting'

export default {
  get: async <T = any>(config: CustomAxiosRequestConfig) => {
    const res = await service({ method: 'GET', ...config })
    return res.data as unknown as T
  },
  post: async <T = any>(config: CustomAxiosRequestConfig) => {
    const res = await service({ method: 'POST', ...config })
    return res.data as unknown as T
  },
  postOriginal: async (config: CustomAxiosRequestConfig) => {
    const res = await service({ method: 'POST', ...config })
    return res
  },
  delete: async <T = any>(config: CustomAxiosRequestConfig) => {
    const res = await service({ method: 'DELETE', ...config })
    return res.data as unknown as T
  },
  put: async <T = any>(config: CustomAxiosRequestConfig) => {
    const res = await service({ method: 'PUT', ...config })
    return res.data as unknown as T
  },
  download: async <T = any>(config: CustomAxiosRequestConfig) => {
    const res = await service({ method: 'GET', responseType: 'blob', ...config })
    return res as unknown as Promise<T>
  },
  upload: async <T = any>(config: CustomAxiosRequestConfig) => {
    if (!config.is_mock) {
      config.headers = {
        'Content-Type': 'multipart/form-data'
      }
    }
    const res = await service({ method: 'POST', ...config })
    return res as unknown as Promise<T>
  }
}
